/-app
TopLayout.ts
main.css
start.ts
/-docs
/-files ...
FileTree.css
FileTree.ts
/-imports
/-persistence
/-typings
errors.js
functions.ts
index.html
try.js
xxxxxxxxxx
 
52
    }
53
    
54
    private _createFile(file: string): Node {
55
      var lastSlashPos = file.lastIndexOf('/');
56
      if (lastSlashPos) { // slash in position other than lead
57
        var parentDir = file.slice(1, lastSlashPos);
58
        var fileName = file = file.slice(lastSlashPos + 1);
59
        var parent = this._virtualRoot.findOrCreateDir(parentDir);
60
        var node = parent.createFile(fileName);
61
        return node;
62
      }
63
      else { 
64
        return this._virtualRoot.createFile(file.slice(1));
65
      }
66
    }
67
    
68
    private _onClick(e: MouseEvent) {
69
      var node = this._getNode(<any>e.target);
70
      if (!node) return;
71
      if (node === this._virtualRoot) return;
72
      
73
      if (node.isDir) {
74
        node.toggleCollapse();
75
      }
76
      else {
77
        this._selectFileNode(node);
78
      }
79
      
80
    }
81
    
82
    private _selectFileNode(node: Node) {
83
      if (this._selectedFileNode) {
84
        this._selectedFileNode.setSelectClass(false);
85
      }
86
      
87
      this._selectedFileNode = node;
88
      if (node) {
89
        this.selectedFile(node.fullPath);
90
        this._selectedFileNode.setSelectClass(true);
91
      }
92
      else {
93
        this.selectedFile(null);
94
      }
95
    }
96
    
97
    private _getNode(elem: HTMLElement): Node {
98
      while (elem) {
99
        var node = (<any>elem)._teapo_node;
100
        if (node) return node;
101
        elem = elem.parentElement;
102
        if (!elem)
103
          return null;
104
      }
105
    }
106
​
107
  }
108
​
109
  class Node {
110
​
111
    isDir: boolean = false;
112
    name: string = null;
113
    fullPath: string = null;
114
​
115
    private _contentPRE: HTMLPreElement = null;
116
    private _subDirs: Node[] = [];
117
    private _files: Node[] = [];
118
    private _ul: HTMLUListElement = null;
119
    
120
    constructor(
121
      public parent: Node,
122
      public li: HTMLElement,
123
      allFiles: { [file: string]: Node; }) {
124
        
125
      (<any>li)._teapo_node = this;
126
​
127
      var childLIs: HTMLLIElement[] = [];
128
      for (var i = 0; i < this.li.children.length; i++) {
129
​
130
        var child = this.li.children[i];
131
        if ((<HTMLLIElement>child).tagName === 'LI') childLIs.push(<HTMLLIElement>child);
132
        if ((<HTMLUListElement>child).tagName === 'UL') {
133
          this._ul = <HTMLUListElement>child;
134
          for (var j = 0; j < this._ul.children.length; j++) {
70:45